package com.hymall.controller.admin;

import com.hymall.bean.MarketAd;
import com.hymall.bean.common.BasePageInfo;
import com.hymall.bean.common.BaseRespVo;
import com.hymall.bean.common.CommonData;
import com.hymall.service.admin.AdService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author 长平居士 - rolfcui@outlook.com
 * @description 推广管理 -> 广告模块
 * @date 2022/7/16 16:36
 */
@RestController
@RequestMapping("admin/ad")
public class AdminAdController {

    @Autowired
    AdService adService;

    @GetMapping("list")
    public BaseRespVo list(String name, String content, BasePageInfo info) {
        CommonData<MarketAd> data = adService.query(name, content, info);
        return BaseRespVo.ok(data);
    }

    @PostMapping("create")
    public BaseRespVo create(@RequestBody MarketAd adItem) {
        adService.create(adItem);
        return BaseRespVo.ok(null);
    }

    @PostMapping("update")
    public BaseRespVo update(@RequestBody MarketAd adItem) {
        adService.updateByClass(adItem);
        return BaseRespVo.ok(null);
    }

    @PostMapping("delete")
    public BaseRespVo delete(@RequestBody MarketAd adItem) {
        adService.delById(adItem.getId());
        return BaseRespVo.ok(null);
    }

}
